package com.polaris.live.ui.main.adapter

import androidx.core.content.ContextCompat
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.constant.AppConst
import com.polaris.live.common.ext.formatNumberWithK
import com.polaris.live.constant.UserRankConst.TYPE_CHARM
import com.polaris.live.constant.UserRankConst.TYPE_RICH
import com.polaris.live.databinding.ItemDailyListBinding
import com.polaris.live.resp.back_resp.PartyGameResp
import com.polaris.live.resp.bean.UserRankItemVo
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * MonthListAdapter
 *
 * @author Created by lucas on 2023/10/30 17:39
 * @since 1.0.0
 */
class MonthListAdapter(
    private val type: Int,
    private val gameResp: PartyGameResp? = null,
) :
    BaseBindingAdapter<ItemDailyListBinding, UserRankItemVo>() {

    override fun convert(holder: VBViewHolder<ItemDailyListBinding>, item: UserRankItemVo) {
        holder.vb.apply {
            ivUserHead.setImageUrl(item.user.avatar, item.user.userId)
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.user.avatarFrame))
            tvUserName.text = item.user.nickname
            tvUserName.setNicknameColor(
                item.user.nicknameColor,
                R.color.color_b2ffffff
            )
            tvCountry.setCountry(item.user.country)
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.user.avatarFrame))
            val sex = if (gameResp != null) {
                item.user.sex
            } else {
                when (type) {
                    TYPE_CHARM -> AppConst.UserSex.WOMAN
                    TYPE_RICH -> AppConst.UserSex.MAN
                    else -> item.user.sex
                }
            }
            vipView.setVipLevel(item.user.vipLevel)
            tvLevel.setRichCharmBySexLevel(sex, item.user.richs, item.user.charms)
            tvCoins.text = item.score.formatNumberWithK()

            if (type != TYPE_CHARM) {
                val drawable = ContextCompat.getDrawable(context, R.drawable.icon_diamond)
                tvCoins.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null)
            }
            if (gameResp != null) {
                tvCoins.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
            }

            tvNum.text = "${holder.layoutPosition + 3}"
        }
    }
}